package com.bootdo.mall.dao;

import com.bootdo.mall.domain.GoodSpecs;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 商品规格
 * @author haojiangbo
 * @email 2100272728@qq.com
 * @date 2019-11-08 16:19:17
 */
@Mapper
public interface GoodSpecsDao {

	GoodSpecs get(Long id);
	
	List<GoodSpecs> list(Map<String,Object> map);

	@Update("update mall_good_specs set stock = stock + #{stock} , sales_num = sales_num - #{stock} where id = #{id} ")
	int  addStock(@Param("stock")Integer stock,@Param("id")Long id);

	@Update("update mall_good_specs set stock = stock - #{stock} , sales_num = sales_num + #{stock} where id = #{id} and stock >= #{stock} ")
	int  delStock(@Param("stock")Integer stock,@Param("id")Long id);

	@Select("select sum (sales_num) as num from mall_good_specs where good_id = #{goodId} ")
	Long getSalesNumByGoodId(Long goodId);
	
	int count(Map<String,Object> map);
	
	int save(GoodSpecs goodSpecs);
	
	int update(GoodSpecs goodSpecs);
	
	int remove(Long id);
	
	int batchRemove(Long[] ids);
}
